﻿<%@ Page Language="C#" MasterPageFile="~/SimplePMTModal.Master" AutoEventWireup="true" CodeBehind="TaskContainerView.aspx.cs" Inherits="SimplePMT.TaskContainerView" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <%= taskContainerView %>
    </p>
    <script>
    
        var tmpId = '';
        var df = document.taskContainerForm;
        var sn = true;
        
        function selectAll(io) {
            for(i=0;i<taskArray.length;i++) {
                taskArray[i].checked = io.checked;
            }
        }
        function clearTaskBuffer() {
            SimplePMT.TaskContainerView.ClearTasksFromBuffer(function(response) {
                alert('The previous task move operation has been canceled successfully.');
                location.reload();
            });
        }
        
        function completeMove() {
            var id = document.containerForm.TaskContainerID.value;
            
            SimplePMT.TaskContainerView.MoveTasksFromBuffer(id, taskIdArray, function(response) {
                if (response.error != null) {
                    alert(response.error.Message);
                } else {
                    alert('Tasks moved successfully.');
                    top.location.reload();
                }
            });
            
        }
        
        function moveSelected() {
            var chk = false;
            var idList = new Array();
            var c = 0;
            for(i=0;i<taskArray.length;i++) {
                if (taskArray[i].checked) {
                    chk = true;
                    idList[c] = parseInt(taskArray[i].value);
                    c++;
                }
            }
            if (chk) {
                SimplePMT.TaskContainerView.MoveTasksToBuffer(idList, function(response) {
                    if (response.error != null) {
                        alert(response.error.Message);
                    } else {
                        alert('The tasks have been marked for moving.\n\nPlease navigate to the folder/container you would like\nto move the tasks to and click edit to complete the move.');
                        top.win.close();
                    }
                });
            } else {
                alert('You must select at least one task to move.');
            }
        }
        
        function showHideMoveOptions() {
            var mo = document.getElementById('moveOptionsContainer');
            var io = document.moveOptionsImage;
            var imgName = io.src.split('/')[io.src.split('/').length - 1];
            if (imgName == 'closed.gif') {
                io.src = 'images/open.gif';
                mo.style.display = 'inline';
            } else {
                io.src = 'images/closed.gif';
                mo.style.display = 'none';
            }
        }
        function confirmDelete(id, pid) {
            if (confirm('Are you sure you want to delete this container?\n\n(All sub-containers and tasks will be completely removed)')) {
                SimplePMT.TaskContainerView.DeleteTaskContainer(id, function(response) {
                    if (response.error != null) {
                        alert(response.error.Message);
                    }
                    if (response.value) {
                        alert('Container deleted successfully.');
                        if (pid == 0) {
                            top.location.reload();
                        } else {
                            top.document.getElementById('container' + top.tmpid).innerHTML = '';
                            top.tmpio.src = 'images/closed.gif';
                            top.loadTree(top.tmpid, top.tmpio);
                            top.win.close();
                        }
                    }
                });
            }
        }
        
        function saveTaskContainer(taskContainerId, parentTaskContainerId, label, description, createMemberId, includeInProjectPlan) {
            SimplePMT.TaskContainerView.SaveTaskContainer(taskContainerId, parentTaskContainerId, label, description, createMemberId, includeInProjectPlan, function(response) {
                if (response.value[0]) {
                    if (taskContainerId == 0 && parentTaskContainerId ==0) {
                        top.location.reload();
                    } else {
                        if (parentTaskContainerId == 0) {
                            top.location.reload();
                        } else { 
                            top.reloadParentNode(<%= parentContainerId %>, top.document.img<%= parentContainerId %>);
                            top.win.close();    
                        }
                    }
                } else {
                    alert(response.error.Message);
                }
            });
        }
    </script>
</asp:Content>